//
//  UIBarButtonItem+Extension.m
//  gold
//
//  Created by LiuYihua on 2016/12/12.
//  Copyright © 2016年 南京斯布乔信息科技有限公司. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)

+ (instancetype) itemWithTitle:(NSString * )title image:(UIImage *)image highImage:(UIImage *)highImage target:(id)target action:(SEL)action alignmentRight:(BOOL)alignmentRight{
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:image forState:UIControlStateNormal];
    [button setImage:highImage forState:UIControlStateHighlighted];
    
    button.titleLabel.font = [UIFont fontWithName:@"Helvetica" size:17];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    [button sizeToFit];
    
    [button setFrame:CGRectMake(0, 0, button.frame.size.width + 5, button.frame.size.height)];
    
    if (alignmentRight) {
        
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        
    }else{
        
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    }
    
    
    return [[self alloc] initWithCustomView:button];
}



@end


